CXX      = g++
LIBS     =  -ldl
DEFS     = -DHAVE_CONFIG_H
LFLAGS   = -m32 -w -fPIC -shared -W -Wall 
CFLAGS   = -mtune=i386 -pipe -g -O2 -m32 -Iinclude $(DEFS)
CPPFLAGS = -mtune=i386 -pipe  -m32 -Iinclude $(DEFS)

# Add your own plugins to the compilation with this configure option:
# ./configure --with-extraplugins="plugin1 plugin2 ..."
SUBDIRS = \
    plugins/Planner

LIBRARY = \
    lib/nwn_data.o     \
    lib/nwn_funcs.o    \
    lib/nwn_hooks.o    \
    lib/nx_hook.o      \
    lib/nx_log.o       \
    lib/nx_safe.o      \
    lib/nx_signature.o


all: nwnx2.so subdirs

nwnx2.so: nwnx2lib.o NWNXBase.o gline.o $(LIBRARY)
	$(CXX) $(LFLAGS) -o $@ $^ $(LIBS)

# always execute regardless of existance or timestamp
.PHONY: clean subdirs $(SUBDIRS)

subdirs: $(SUBDIRS)

$(SUBDIRS):
	$(MAKE) -C $@ PLUGIN_CFLAGS="$(CFLAGS)" PLUGIN_CPPFLAGS="$(CPPFLAGS)" PLUGIN_LFLAGS="$(LFLAGS)"

clean:
	for i in $(SUBDIRS); do $(MAKE) -C $$i $@; done
	/bin/rm -f *.o *.so lib/*.o *~

install: all
	for i in $(SUBDIRS); do $(MAKE) -C $$i $@; done
	mkdir -p /usr/local/share/nwn/
	install nwnx2.so /usr/local/share/nwn/
	if [ ! -f /usr/local/share/nwn/nwnx2.ini ]; then install nwnx2.ini /usr/local/share/nwn/; fi

distclean:
	for i in $(SUBDIRS); do $(MAKE) -C $$i $@; done
	/bin/rm -f Makefile config.h config.status config.cache config.log *.o *.so lib/*.o *~

